/*
 * EasyBounceRankDataReader.cpp
 *
 *  Created on: May 21, 2009
 *      Author: Cedric
 */

//includes
#include <f32file.h> 
#include <utf.h>
#include <COEMAIN.H>
#include "EasyBounceRankDataReader.h"

_LIT( KFileName, "c:\\ebrank.txt");

// ============================ MEMBER FUNCTIONS ===============================

// -----------------------------------------------------------------------------
// CEasyBounceDataReader::~CEasyBounceDataReader()
// destructor
// -----------------------------------------------------------------------------
//
CEasyBounceDataReader::~CEasyBounceDataReader()
	{
	Cancel();
	iRankDataFile.Close();
	delete iRankData;
	iRankData = NULL;
	delete iRawRankData;
	iRawRankData = NULL;
	}

// -----------------------------------------------------------------------------
// CEasyBounceDataReader::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CEasyBounceDataReader* CEasyBounceDataReader::NewLC()
	{
	CEasyBounceDataReader* self = new (ELeave) CEasyBounceDataReader();
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
	}

// -----------------------------------------------------------------------------
// CEasyBounceDataReader::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CEasyBounceDataReader* CEasyBounceDataReader::NewL()
	{
	CEasyBounceDataReader* self = CEasyBounceDataReader::NewLC();
	CleanupStack::Pop(self);
	return self;
	}

// -----------------------------------------------------------------------------
// CEasyBounceDataReader::ReadDataL()
// Asychronously read file using active object
// -----------------------------------------------------------------------------
//
void CEasyBounceDataReader::ReadDataL()
	{
	User::LeaveIfError(iRankDataFile.Open(iFs, KFileName, EFileRead));
	iRankDataFile.Read(*iRawRankData, iStatus);
	SetActive();
	}

// -----------------------------------------------------------------------------
// CEasyBounceDataReader::CEasyBounceDataReader()
// Default constructor
// -----------------------------------------------------------------------------
//
CEasyBounceDataReader::CEasyBounceDataReader() : CActive (EPriorityStandard)
	{
	//initialise active object with default priority
	//add this active object to active scheduler
	CActiveScheduler::Add(this);
	}

// -----------------------------------------------------------------------------
// CEasyBounceDataReader::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CEasyBounceDataReader::ConstructL()
	{
	//TODO: initialize file session
	iFs = CCoeEnv::Static()->FsSession();
	iRawRankData = new TBuf8<KMaxLength>;
	}

// -----------------------------------------------------------------------------
// CEasyBounceDataReader::RunL()
// Called by Active Scheduler when data read completed
// -----------------------------------------------------------------------------
//
void CEasyBounceDataReader::RunL()
	{
	if( iStatus != KErrNone )
		{
		_LIT(KPanicTExt, "Error Reading File");
		User::Leave(KErrGeneral);
		}
	
	//TODO:update ranklist

	//TODO:redraw listbox

	}

// -----------------------------------------------------------------------------
// CEasyBounceDataReader::DoCancel()
// Called by Active::Cancel() when destructing 
// -----------------------------------------------------------------------------
//
void CEasyBounceDataReader::DoCancel()
	{
	iRankDataFile.ReadCancel(iStatus);
	iRankDataFile.Close();
	}

// -----------------------------------------------------------------------------
// CEasyBounceDataReader::DoCancel()
// Called by Active Scheduler when leave happens at RunL()
// -----------------------------------------------------------------------------
//
TInt CEasyBounceDataReader::RunError()
	{
	User::Leave(KErrGeneral);
	}

//end of file
//iRankContainer->RankList()->UpdateRankData(iRawRankData);
//iRankContainer->ListBox()->DrawNow();

